﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Npgsql;
using System.Configuration;
using System.Data;

namespace IonosphereViewer
{
    public partial class ClientInfoPage : System.Web.UI.Page
    {
        DataSet myDS = new DataSet();
        NpgsqlConnection conn;
        //TODO: написать запросы
        //--------------------------------------------------------------------------
        const string SqlSFiles =
            @"SELECT 
              id,
              measure_date,
              seans,
              nr1,
              nr2,
              measure_type,
              date_modify,
              user_id
            FROM 
              public.headerall";
        //--------------------------------------------------------------------------
        const string SqlSFilesNew =
            @"SELECT 
              id,
              measure_date,
              seans,
              nr1,
              nr2,
              measure_type,
              date_modify,
              user_id
            FROM 
              public.headerall";
        //--------------------------------------------------------------------------
        const string SqlVFiles =
            @"SELECT 
              id,
              measure_date,
              seans,
              nr1,
              nr2,
              measure_type,
              date_modify,
              user_id
            FROM 
              public.headerall";
        //--------------------------------------------------------------------------
        const string SqlIonogramma =
            @"SELECT 
              id,
              measure_date,
              seans,
              nr1,
              nr2,
              measure_type,
              date_modify,
              user_id
            FROM 
              public.headerall";
        //--------------------------------------------------------------------------
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Error += new EventHandler(_Default_Error);
            //TODO: подумать, каждый раз или один раз
            this.conn = new NpgsqlConnection(LoginPage.constring);
            conn.Open();
            FillGrid(SqlSFiles); 
        }
        //--------------------------------------------------------------------------
        private void FillGrid(string sSql)
        {
            try
            {
                NpgsqlCommand comm = new NpgsqlCommand(sSql, this.conn);
                NpgsqlDataAdapter da = new NpgsqlDataAdapter(comm);

                da.Fill(myDS);
                DataTable dt = myDS.Tables[0];

                DataGridInfo.DataSource = dt;
                DataGridInfo.DataBind();

            }
            finally
            {
                conn.Close();
            }
 
        }
        //--------------------------------------------------------------------------
        protected void ButtonStat_Click(object sender, EventArgs e)
        {
            string theInfo = "";
            theInfo += String.Format("<Li> Is the client AOL? {0}", Request.Browser.AOL);
            theInfo += String.Format("<Li> Does the client support ActiveX? {0}", Request.Browser.ActiveXControls);
            theInfo += String.Format("<Li> Is the client a Beta? {0}", Request.Browser.Beta);
            theInfo += String.Format("<Li> Does the client support Java Applets? {0}", Request.Browser.JavaApplets);
            theInfo += String.Format("<Li> Does the client support Cookies? {0}", Request.Browser.Cookies);
            theInfo += String.Format("<Li> Does the client support VBScript? {0}", Request.Browser.VBScript);
            //LabelInfo.Text = theInfo;
            Response.Write("Была получена информация о браузере клиента.");
        }
        //--------------------------------------------------------------------------
        void _Default_Error(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Write("Page Error!<br />");
            Response.Write(string.Format("Error: <b>{0}</b>", Server.GetLastError().Message));
            Server.ClearError();
        }
        //--------------------------------------------------------------------------
        protected void MainMenu_MenuItemClick(object sender, MenuEventArgs e)
        {
            string sSQL = String.Empty;;
            if ((sender is Menu) &&
                (sender != null))
            {
                if ((sender as Menu).SelectedValue == "SFiles")
                {
                    sSQL = SqlSFiles;
                }
                if ((sender as Menu).SelectedValue == "SFilesNew")
                {
                    sSQL = SqlSFilesNew;
                }
                if ((sender as Menu).SelectedValue == "VFiles")
                {
                    sSQL = SqlVFiles;
                }
                if ((sender as Menu).SelectedValue == "Ionogramma")
                {
                    sSQL = SqlIonogramma;
                }
            }

            FillGrid(sSQL); 
        }
        //--------------------------------------------------------------------------
    }
}
